/**
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，pro版只支持remixIcon图标，具体配置请查看vip群文档
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/vab/layouts'
import {publicPath, routerMode} from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/callback',
    component: () => import('@/views/callback'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/403',
    name: '403',
    component: () => import('@/views/403'),
    meta: {
      hidden: true,
    },
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    meta: {
      hidden: true,
    },
  },
]

export const asyncRoutes = [
  // {
  //   path: '/Root',
  //   name: 'Root',
  //   component: Layout,
  //   meta: {
  //     title: '首页',
  //     icon: 'home-2-line',
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'index',
  //       component: () => import('@/views/root/express'),
  //       meta: {
  //         title: '首页',
  //         icon: 'home-2-line',
  //         noClosable: true,
  //       },
  //     },
  //   ],
  // },


  {
    path: '*',
    name: 'Toolbox',
    component: Layout,
    meta: {
      title: '工具箱',
      icon: 'tools-fill ',
      roles: ['1']
    },
    children: [
      {
        path: '/vab',
        name: 'Vab',
        component: Layout,
        redirect: '/vab/icon/remixIcon',
        meta: {
          title: '组件',
          hidden: false,
          icon: 'code-box-line',
        },
        children: [
          {
            path: 'icon',
            name: 'Icon',
            redirect: '/vab/icon/remixIcon',
            meta: {
              title: '图标',
              icon: 'remixicon-line',
            },
            children: [
              {
                path: 'remixIcon',
                name: 'RemixIcon',
                component: () => import('@/views/vab/icon/remixIcon'),
                meta: {
                  title: '小清新图标',
                },
              },
              {
                path: 'iconSelector',
                name: 'IconSelector',
                component: () => import('@/views/vab/icon/iconSelector'),
                meta: {
                  title: '图标选择器',
                },
              },
            ],
          },
          {
            path: 'roles',
            name: 'Role',
            component: () => import('@/views/vab/roles'),
            meta: {
              title: '角色权限',
              icon: 'user-3-line',
              badge: 'Pro',
            },
          },
          {
            path: 'table',
            name: 'Table',
            redirect: '/vab/table/comprehensiveTable',
            meta: {
              title: '表格',
              // 非editor角色的用户可见
              roles: {
                role: ['editor'],
                mode: 'except',
              },
              icon: 'table-2',
            },
            children: [
              {
                path: 'comprehensiveTable',
                name: 'ComprehensiveTable',
                component: () => import('@/views/vab/table/comprehensiveTable'),
                meta: {
                  title: '综合表格',
                },
              },
              {
                path: 'detail',
                name: 'Detail',
                component: () => import('@/views/vab/table/detail'),
                meta: {
                  hidden: true,
                  title: '详情页',
                  activeMenu: '/vab/table/comprehensiveTable',
                  dynamicNewTab: true, //详情页根据id传参不同可打开多个
                },
              },
              {
                path: 'inlineEditTable',
                name: 'InlineEditTable',
                component: () => import('@/views/vab/table/inlineEditTable'),
                meta: {
                  title: '行内编辑表格',
                  noKeepAlive: true,
                },
              },
              {
                path: 'customTable',
                name: 'CustomTable',
                component: () => import('@/views/vab/table/customTable'),
                meta: {
                  title: '自定义表格',
                },
              },
            ],
          },
          {
            path: 'card',
            name: 'Card',
            component: () => import('@/views/vab/card'),
            meta: {
              title: '卡片',
              //roles: ['admin'],
              icon: 'inbox-line',
            },
          },
          {
            path: 'list',
            name: 'List',
            component: () => import('@/views/vab/list'),
            meta: {
              title: '列表',
              //roles: ['admin'],
              icon: 'list-check-2',
            },
          },
          {
            path: 'form',
            name: 'Form',
            meta: {
              title: '表单',
              //roles: ['admin'],
              icon: 'file-list-2-line',
            },
            children: [
              {
                path: 'comprehensiveForm',
                name: 'ComprehensiveForm',
                component: () => import('@/views/vab/form/comprehensiveForm'),
                meta: {
                  title: '综合表单',
                },
              },
              {
                path: 'stepForm',
                name: 'StepForm',
                component: () => import('@/views/vab/form/stepForm'),
                meta: {
                  title: '分步表单',
                },
              },
              {
                path: 'button',
                name: 'Button',
                component: () => import('@/views/vab/form/button'),
                meta: {
                  title: '按钮',
                },
              },
              {
                path: 'link',
                name: 'Link',
                component: () => import('@/views/vab/form/link'),
                meta: {
                  title: '文字链接',
                },
              },
              {
                path: 'radio',
                name: 'Radio',
                component: () => import('@/views/vab/form/radio'),
                meta: {
                  title: '单选框',
                },
              },
              {
                path: 'checkbox',
                name: 'Checkbox',
                component: () => import('@/views/vab/form/checkbox'),
                meta: {
                  title: '多选框',
                },
              },
              {
                path: 'input',
                name: 'Input',
                component: () => import('@/views/vab/form/input'),
                meta: {
                  title: '输入框',
                },
              },
              {
                path: 'inputNumber',
                name: 'InputNumber',
                component: () => import('@/views/vab/form/inputNumber'),
                meta: {
                  title: '计数器',
                },
              },
              {
                path: 'select',
                name: 'Select',
                component: () => import('@/views/vab/form/select'),
                meta: {
                  title: '选择器',
                },
              },
              {
                path: 'switch',
                name: 'Switch',
                component: () => import('@/views/vab/form/switch'),
                meta: {
                  title: '开关',
                },
              },
              {
                path: 'slider',
                name: 'Slider',
                component: () => import('@/views/vab/form/slider'),
                meta: {
                  title: '滑块',
                },
              },
              {
                path: 'timePicker',
                name: 'TimePicker',
                component: () => import('@/views/vab/form/timePicker'),
                meta: {
                  title: '时间选择器',
                },
              },
              {
                path: 'datePicker',
                name: 'DatePicker',
                component: () => import('@/views/vab/form/datePicker'),
                meta: {
                  title: '日期选择器',
                },
              },
              {
                path: 'dateTimePicker',
                name: 'DateTimePicker',
                component: () => import('@/views/vab/form/dateTimePicker'),
                meta: {
                  title: '日期时间选择器',
                },
              },
              {
                path: 'rate',
                name: 'Rate',
                component: () => import('@/views/vab/form/rate'),
                meta: {
                  title: '评分',
                },
              },
            ],
          },
          {
            path: 'editor',
            name: 'Editor',
            meta: {
              title: '编辑器',
              //roles: ['admin'],
              icon: 'edit-2-line',
            },
            children: [
              {
                path: 'richTextEditor',
                name: 'RichTextEditor',
                component: () => import('@/views/vab/editor/richTextEditor'),
                meta: {
                  title: '富文本编辑器',
                  //roles: ['admin'],
                },
              },
              {
                path: 'markdownEditor',
                name: 'MarkdownEditor',
                component: () => import('@/views/vab/editor/markdownEditor'),
                meta: {
                  title: 'Markdown编辑器',
                  //roles: ['admin'],
                },
              },
            ],
          },
        ],
      },
      {
        path: '/other',
        name: 'Other',
        component: Layout,
        redirect: '/other/workflow',
        meta: {
          title: '其他',
          icon: 'archive-line',
          hidden: false,
          //roles: ['admin'],
        },
        children: [
          {
            path: 'workflow',
            name: 'Workflow',
            component: () => import('@/views/other/workflow'),
            meta: {
              title: '工作流',
              //roles: ['admin'],
              icon: 'flow-chart',
            },
          },
          {
            path: 'echarts',
            name: 'Echarts',
            component: () => import('@/views/other/echarts'),
            meta: {
              title: '图表',
              //roles: ['admin'],
              icon: 'bubble-chart-line',
            },
          },
          {
            path: 'print',
            name: 'Print',
            component: () => import('@/views/other/print'),
            meta: {
              title: '打印',
              //roles: ['admin'],
              icon: 'printer-line',
            },
          },
          {
            path: 'cropper',
            name: 'Cropper',
            component: () => import('@/views/other/cropper'),
            meta: {
              title: '头像裁剪',
              //roles: ['admin'],
              icon: 'crop-line',
            },
          },
          {
            path: 'notice',
            name: 'Notice',
            component: () => import('@/views/other/notice'),
            meta: {
              title: '通知',
              //roles: ['admin'],
              icon: 'message-2-line',
            },
          },
          {
            path: 'timeline',
            name: 'Timeline',
            component: () => import('@/views/other/timeline'),
            meta: {
              title: '时间线',
              //roles: ['admin'],
              icon: 'time-line',
            },
          },
          {
            path: 'count',
            name: 'Count',
            component: () => import('@/views/other/count'),
            meta: {
              title: '数字自增长',
              //roles: ['admin'],
              icon: 'number-9',
            },
          },
          {
            path: 'tabs',
            name: 'tabs',
            component: () => import('@/views/other/tabs'),
            meta: {
              title: '多标签',
              //roles: ['admin'],
              icon: 'bank-card-line',
            },
          },
          {
            path: 'dynamicMeta',
            name: 'DynamicMeta',
            component: () => import('@/views/other/dynamicMeta'),
            meta: {
              title: '动态Meta',
              //roles: ['admin'],
              icon: 'notification-badge-line',
              badge: '0',
            },
          },
          {
            path: 'dynamicSegment',
            name: 'DynamicSegment',
            redirect: '/other/dynamicSegment/test1/1',
            meta: {
              title: '动态路径参数',
              //roles: ['admin'],
              icon: 'arrow-left-right-line',
            },
            children: [
              {
                path: 'test1/:id',
                name: 'Test1',
                component: () => import('@/views/other/dynamicSegment/test1'),
                meta: {
                  hidden: true,
                  title: 'Params',
                  dynamicNewTab: true,
                },
              },
              {
                path: 'test1/1',
                name: 'test1/1',
                component: () => import('@/views/other/dynamicSegment/test1'),
                meta: {title: 'Params id=1'},
              },
              {
                path: 'test2',
                name: 'Test2',
                component: () => import('@/views/other/dynamicSegment/test2'),
                meta: {
                  hidden: true,
                  title: 'Query',
                  dynamicNewTab: true,
                },
              },
              {
                path: 'test2?id=1',
                name: 'test2?id=1',
                component: () => import('@/views/other/dynamicSegment/test2'),
                meta: {title: 'Query id=1'},
              },
            ],
          },
          {
            path: 'drag',
            name: 'Drag',
            redirect: '/vab/drag/dialogDrag',
            meta: {
              title: '拖拽',
              // hidden:false,
              //roles: ['admin'],
              icon: 'drag-drop-line',
            },
            children: [
              {
                path: 'dialogDrag',
                name: 'DialogDrag',
                component: () => import('@/views/other/drag/dialogDrag'),
                meta: {
                  title: '弹窗拖拽',
                },
              },
              {
                path: 'cardDrag',
                name: 'CardDrag',
                component: () => import('@/views/other/drag/cardDrag'),
                meta: {
                  title: '卡片拖拽',
                },
              },
              {
                path: 'flowSheetDrag',
                name: 'FlowSheetDrag',
                component: () => import('@/views/other/drag/flowSheetDrag'),
                meta: {
                  title: '流程图拖拽',
                  noKeepAlive: true,
                },
              },
            ],
          },
          {
            path: 'contextmenu',
            name: 'Contextmenu',
            component: () => import('@/views/other/contextmenu'),
            meta: {
              title: '右键菜单',
              //roles: ['admin'],
              icon: 'menu-2-fill',
            },
          },
          {
            path: 'loading',
            name: 'Loading',
            component: () => import('@/views/other/loading'),
            meta: {
              title: '加载',
              //roles: ['admin'],
              icon: 'loader-line',
            },
          },
          {
            path: 'player',
            name: 'Player',
            component: () => import('@/views/other/player'),
            meta: {
              title: '视频播放器',
              //roles: ['admin'],
              icon: 'video-line',
              noKeepAlive: true,
            },
          },
          {
            path: 'upload',
            name: 'Upload',
            component: () => import('@/views/other/upload'),
            meta: {
              title: '上传',
              //roles: ['admin'],
              icon: 'chat-upload-line',
            },
          },
          {
            path: 'menu1',
            name: 'Menu1',
            redirect: '/other/menu1/menu1-1/menu1-1-1/menu1-1-1-1',
            meta: {
              title: '多级路由缓存',
              //roles: ['admin'],
              icon: 'route-line',
            },
            children: [
              {
                path: 'menu1-1',
                name: 'Menu11',
                redirect: '/other/menu1/menu1-1/menu1-1-1/menu1-1-1-1',
                meta: {
                  title: '多级路由1-1',
                },
                children: [
                  {
                    path: 'menu1-1-1',
                    name: 'Menu111',
                    redirect: '/other/menu1/menu1-1/menu1-1-1/menu1-1-1-1',
                    meta: {
                      title: '多级路由1-1-1',
                    },
                    children: [
                      {
                        path: 'menu1-1-1-1',
                        name: 'Menu1111',
                        meta: {
                          title: '多级路由1-1-1-1',
                        },
                        component: () =>
                          import(
                            '@/views/other/nested/menu1/menu1-1/menu1-1-1/menu1-1-1-1'
                            ),
                      },
                    ],
                  },
                ],
              },
            ],
          },
          {
            path: 'log',
            name: 'Log',
            component: () => import('@/views/other/errorLog'),
            meta: {
              title: '错误日志模拟',
              //roles: ['admin'],
              icon: 'error-warning-line',
            },
          },
          {
            path: 'cssfx',
            name: 'Cssfx',
            component: () => import('@/views/other/cssfx'),
            meta: {
              title: 'Css动画',
              //roles: ['admin'],
              icon: 'css3-line',
            },
          },
          {
            path: 'social',
            name: 'Social',
            component: () => import('@/views/other/social'),
            meta: {
              title: '第三方登录',
              //roles: ['admin'],
              icon: 'github-fill',
            },
          },
          // {
          //   path: 'mobilePreview',
          //   name: 'MobilePreview',
          //   component: () => import('@/views/vab/mobilePreview'),
          //   meta: {
          //     title: '手机预览',
          //     //roles: ['admin'],
          //     icon: 'smartphone-line',
          //   },
          // },
          {
            path: '//github.com/chuzhixin/vue-admin-beautiful?utm_source=gold_browser_extension',
            name: 'ExternalLink',
            meta: {
              title: '外链',
              target: '_blank',
              // 等价roles: ['admin', 'editor'],
              roles: {
                role: ['admin', 'editor'],
                mode: 'oneOf',
              },
              icon: 'external-link-line',
            },
          },
          {
            path: 'iframe',
            name: 'Iframe',
            redirect: '/other/iframe/search',
            meta: {
              title: 'Iframe',
              //roles: ['admin'],
              icon: 'window-line',
            },
            children: [
              {
                path: 'view',
                name: 'IframeView',
                component: () => import('@/views/other/iframe/view'),
                meta: {
                  hidden: true,
                  title: 'Iframe',
                  icon: 'window-line',
                  dynamicNewTab: true,
                },
              },
              {
                path: 'view?url=https%3A%2Fwww.baidu.com&title=%E7%99%BE%E5%BA%A6',
                name: 'baiduIframe',
                component: () => import('@/views/other/iframe/view'),
                meta: {title: '百度', icon: 'baidu-fill'},
              },
              {
                path: 'view?url=https%3A%2Fgitee.com%2Fchu1204505056%2Fvue-admin-beautiful&title=Gitee',
                name: 'githubIframe',
                component: () => import('@/views/other/iframe/view'),
                meta: {title: 'Gitee', icon: 'github-fill'},
              },
              {
                path: 'search',
                name: 'IframeSearch',
                component: () => import('@/views/other/iframe/search'),
                meta: {
                  title: '自定义Iframe',
                  icon: 'search-2-line',
                },
              },
            ],
          },
          {
            path: 'excel',
            name: 'Excel',
            redirect: '/other/excel/exportExcel',
            meta: {
              title: 'Excel',
              //roles: ['admin'],
              icon: 'file-excel-2-line',
            },
            children: [
              {
                path: 'exportExcel',
                name: 'ExportExcel',
                component: () => import('@/views/other/excel/exportExcel'),
                meta: {
                  title: '导出Excel',
                },
              },
              {
                path: 'exportSelectedExcel',
                name: 'SelectExcel',
                component: () => import('@/views/other/excel/exportSelectExcel'),
                meta: {
                  title: '导出选中行Excel',
                },
              },
              {
                path: 'exportMergeHeaderExcel',
                name: 'MergeHeaderExcel',
                component: () =>
                  import('@/views/other/excel/exportMergeHeaderExcel'),
                meta: {
                  title: '导出合并Excel',
                },
              },
              {
                path: 'upload-excel',
                component: () => import('@/views/other/excel/upload-excel'),
                name: 'UploadExcel',
                meta: {title: 'Upload Excel'}
              }
            ],
          },
        ],
      },
      {
        path: '/mall',
        name: 'Mall',
        component: Layout,
        redirect: '/mall/goods',
        meta: {
          title: '物料源',
          icon: 'apps-line',
          hidden: false,
          //roles: ['admin'],
        },
        children: [
          {
            path: 'goods',
            name: 'Goods',
            component: () => import('@/views/mall/goods'),
            meta: {
              title: '物料市场',
              icon: 'shopping-cart-line',
              badge: 'Hot',
            },
          },
        ],
      },
      {
        path: '/setting',
        name: 'PersonnelManagement',
        component: Layout,
        redirect: '/setting/personalCenter',
        meta: {
          title: '配置',
          icon: 'user-settings-line',
          hidden: true
          //roles: ['admin'],
        },
        children: [
          {
            path: 'personalCenter',
            name: 'PersonalCenter',
            component: () => import('@/views/setting/personalCenter'),
            meta: {
              title: '个人中心',
              icon: 'map-pin-user-line',
            },
          },
          {
            path: 'userManagement',
            name: 'UserManagement',
            component: () => import('@/views/setting/userManagement'),
            meta: {
              title: '用户管理',
              icon: 'user-3-line',
            },
          },
          {
            path: 'roleManagement',
            name: 'RoleManagement',
            component: () => import('@/views/setting/roleManagement'),
            meta: {
              title: '角色管理',
              icon: 'admin-line',
            },
          },
          {
            path: 'departmentManagement',
            name: 'DepartmentManagement',
            component: () => import('@/views/setting/departmentManagement'),
            meta: {
              title: '部门管理',
              icon: 'group-line',
            },
          },
          {
            path: 'menuManagement',
            name: 'MenuManagement',
            component: () => import('@/views/setting/menuManagement'),
            meta: {
              title: '菜单管理',
              icon: 'menu-2-fill',
            },
          },
          {
            path: 'systemLog',
            name: 'SystemLog',
            component: () => import('@/views/setting/systemLog'),
            meta: {
              title: '系统日志',
              icon: 'file-shield-2-line',
            },
          },
        ],
      },
      {
        path: '/error',
        name: 'Error',
        component: Layout,
        redirect: '/error/403',
        meta: {
          title: '错误页',
          icon: 'error-warning-line',
          levelHidden: true,
        },
        children: [
          {
            path: '403',
            name: 'Error403',
            component: () => import('@/views/403'),
            meta: {
              title: '403',
              icon: 'error-warning-line',
              // tabHidden: true,
            },
          },
          {
            path: '404',
            name: 'Error404',
            component: () => import('@/views/404'),
            meta: {
              title: '404',
              icon: 'error-warning-line',
              // tabHidden: true,
            },
          },
        ],
      },
      {
        path: 'root',
        name: 'Root',
        component: Layout,
        meta: {
          title: '首页',
          icon: 'home-2-line',
        },
        children: [
          {
            path: 'index',
            name: 'Index',
            component: () => import('@/views/index'),
            meta: {
              title: '首页',
              icon: 'home-2-line',
            },
          },
          {
            path: 'dashboard',
            name: 'Dashboard',
            component: () => import('@/views/index/dashboard'),
            meta: {
              title: '看板',
              icon: 'dashboard-line',
              badge: 'new',
            },
          },
          {
            path: 'workbench',
            name: 'Workbench',
            component: () => import('@/views/index/workbench'),
            meta: {
              title: '工作台',
              icon: 'settings-6-line',
              dot: true,
            },
          },
        ],
      },
    ]
  },
  {
    path: '/',
    name: 'Order',
    component: Layout,
    meta: {
      title: '销售管理',
      icon: 'exchange-dollar-fill',
      roles:['6','7']
    },
    children: [
      {
        path: 'orderManagement',
        name: 'orderManagement',
        component: () => import('@/views/order/orderManagement'),
        meta: {
          title: '废料销售工单',
          icon: 'delete-bin-3-line',
          roles:['6']
        },
      },
      {
        path: 'orderProManagement',
        name: 'orderProManagement',
        component: () => import('@/views/order/orderProductManagement'),
        meta: {
          title: '产品销售工单',
          icon: 'table-alt-fill',
          roles:['7']
        },
      }
    ],
  },
  {
    path: '/Purchase',
    name: 'Purchase',
    component: Layout,
    meta: {
      title: '采购管理',
      icon: 'hand-coin-fill',
      roles:['8','9']
    },
    children: [
      {
        path: 'in',
        name: 'purchaseIn',
        component: () => import('@/views/purchase/in'),
        meta: {
          title: '废料采购工单',
          icon: 'delete-bin-2-fill',
          roles:['8']
        },
      },
      {
        path: 'product',
        name: 'purchaseProduct',
        component: () => import('@/views/purchase/product'),
        meta: {
          title: '产品采购工单',
          icon: 'list-settings-fill',
          roles:['9']
        },
      }
    ],
  },
  {
    path: '/Quotation',
    name: 'Quotation',
    component: Layout,
    meta: {
      title: '报价记录',
      icon: 'price-tag-3-fill',
      roles:['10','11','12']
    },
    children: [
      {
        path: 'in',
        name: 'QuotationIn',
        component: () => import('@/views/quotation/in'),
        meta: {
          title: '废料报价工单',
          icon: 'delete-bin-5-fill',
          roles:['10']
        },
      },
      {
        path: 'product',
        name: 'QuotationProduct',
        component: () => import('@/views/quotation/product'),
        meta: {
          title: '产品报价工单',
          icon: 'file-list-2-fill',
          roles:['11']
        },
      },
      {
        path: 'tool',
        name: 'QuotationTool',
        component: () => import('@/views/quotation/tool'),
        meta: {
          title: '报价工具',
          icon: 'tools-line',
          roles:['12']
        },
      }
    ],
  },
  {
    path: '/business',
    name: 'Business',
    component: Layout,
    meta: {
      title: '业务维护',
      icon: 'flow-chart',
      roles:['13']
    },
    children: [
      {
        path: 'customer',
        name: 'customer',
        component: () => import('@/views/business/customer'),
        meta: {
          title: '合作方列表',
          icon: 'user-star-line',
          roles:['13']
        },
      },
    ],
  },
  {
    path: '/sku',
    name: 'Sku',
    component: Layout,
    meta: {
      title: 'SKU设置',
      icon: 'apps-2-fill',
      roles:['14','15','16']
    },
    children: [
      {
        path: 'cateValue',
        name: 'cateValue',
        component: () => import('@/views/sku/cateValue'),
        meta: {
          title: '属性设置',
          icon: 'shape-2-line',
          roles:['14']
        },
      },
      {
        path: 'mold',
        name: 'mold',
        component: () => import('@/views/sku/mold'),
        meta: {
          title: '类型管理',
          icon: 'barcode-box-line',
          roles:['15']
        },
      },{
        path: 'classify',
        name: 'classify',
        component: () => import('@/views/sku/classify'),
        meta: {
          title: 'SKU管理',
          icon: 'qr-code-line',
          roles:['16']
        },
      }
    ],
  },
  {
    path: '/bom',
    name: 'Bom',
    component: Layout,
    meta: {
      title: 'BOM管理',
      icon: 'equalizer-line',
      roles:['17','18']
    },
    children: [{
        path: 'order',
        name: 'order',
        component: () => import('@/views/bom/order'),
        meta: {
          title: 'BOM工单',
          icon: 'git-branch-line',
          roles:['17']
        },
      },
      {
        path: 'files',
        name: 'files',
        component: () => import('@/views/bom/files'),
        meta: {
          title: 'BOM档案',
          icon: 'file-paper-fill',
          roles:['18']
        },
      }
    ],
  },
  {
    path: '/manage',
    name: 'Manage',
    component: Layout,
    meta: {
      title: '系统设置',
      icon: 'settings-3-fill',
      roles:['4','2','3']
    },
    children: [
      {
        path: 'personalCenter',
        name: 'personalCenter',
        component: () => import('@/views/manage/personalCenter'),
        meta: {
          title: '个人中心',
          icon: 'account-pin-circle-fill',
        },
      },
      {
        path: 'roleManagement',
        name: 'roleManagement',
        component: () => import('@/views/manage/roleManagement'),
        meta: {
          title: '角色管理',
          icon: 'user-5-fill',
          roles:['2']
        },
      },
      {
        path: 'userManagement',
        name: 'userManagement',
        component: () => import('@/views/manage/userManagement'),
        meta: {
          title: '管理员列表',
          icon: 'folder-user-line',
          roles:['3']
        },
      },
      // {
      //   path: 'systemLog',
      //   name: 'SystemLog',
      //   component: () => import('@/views/manage/systemLog'),
      //   meta: {
      //     title: '系统日志',
      //     icon: 'file-shield-2-line',
      //     roles:['4']
      //   },
      // },
    ],
  },
]

const router = createRouter()

function fatteningRoutes(routes) {
  return routes.flatMap((route) => {
    return route.children ? fatteningRoutes(route.children) : route
  })
}

export function resetRouter(routes = constantRoutes) {
  routes.map((route) => {
    if (route.children) {
      route.children = fatteningRoutes(route.children)
    }
  })
  router.matcher = createRouter(routes).matcher
}

function createRouter(routes = constantRoutes) {
  return new VueRouter({
    base: publicPath,
    mode: routerMode,
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: routes,
  })
}

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch((err) => err)
}

export default router
